#include <cstdio>
#include <queue>
#include <vector>
using namespace std;

struct Node
{
  int parent;
  unsigned int weight;
  
  Node()
  {
    weight = 0;
    parent = -1;
  }
};

struct Side
{
  int u, v, w;
};

struct TrieNode
{
  int next[2];
  unsigned int value;
  TrieNode()
  {
    next[0] = -1;
    next[1] = -1;
    value = 0;
  }
};

inline int getbit( unsigned int k, int p )
{
  return ( k >> p ) & 0x01;
}

unsigned int maxweight( const vector<unsigned int>& nums )
{
  vector<TrieNode> tries;
  tries.push_back( TrieNode() );
  for( size_t i = 0; i < nums.size(); i++ )
  {
    int p = 0;
    for( int j = 30; j >= 0; j-- )
    {
      int d = getbit( nums[i], j );
      if( tries[p].next[d] == -1 )
      {
        tries.push_back( TrieNode() );
        tries[p].next[d] = tries.size() - 1;
      }
      p = tries[p].next[d];
    }
    tries[p].value = nums[i];
  }
  
  int max_weight = 0;
  for( size_t i = 0; i < nums.size(); i++ )
  {
    int p = 0;
    for( int j = 30; j >= 0; j-- )
    {
      int d = getbit( ~nums[i], j );
      if( tries[p].next[d] != -1 )
      {
        p = tries[p].next[d];
      }
      else
      {
        p = tries[p].next[1 - d];
      }
    }
    int weight = nums[i] ^ tries[p].value;
    //printf( "%d^%d=%d\n", nums[i], tries[p].value, weight );
    if( max_weight < weight ) max_weight = weight;
  }
 
  return max_weight;
}

int main()
{
  while(1)
  {
    int n = 0;
    if( scanf( "%d", &n ) != 1 )
    {
      break;
    }
    
    vector<bool> sign( n - 1, false );
    
    vector<Side> sides( n );
    for( int i = 0; i < n - 1; i++ )
    {
      scanf( "%d %d %d", &sides[i].u, &sides[i].v, &sides[i].w );
      if( sides[i].v == 0 || sign[sides[i].v - 1] )
      {
        if( sides[i].u == 0 || sign[sides[i].u - 1] )
        {
          printf( "ERROR!\n" );
        }      
        std::swap( sides[i].u, sides[i].v );
        sign[ sides[i].v - 1 ] = true;
      }
    }
    
    vector<Node> nodes( n );
    for( size_t i = 0; i < sides.size() - 1; i++ )
    {
      nodes[ sides[i].v ].weight = sides[i].w;
      nodes[ sides[i].v ].parent = sides[i].u;
    }
    
    for( size_t i = 0; i < nodes.size(); i++ )
    {
      if( nodes[i].parent == -1 ) continue;
      
      vector<int> traces;
      int p = i;
      while( nodes[p].parent != -1 )
      { 
        traces.push_back( p );
        p = nodes[p].parent;
      }
      
      for( vector<int>::reverse_iterator it = traces.rbegin(); it != traces.rend(); it++ )
      {
        nodes[*it].weight ^= nodes[ nodes[*it].parent ].weight;
        nodes[*it].parent = -1;
      }
    } 
    
    vector<unsigned int> weights;
    for( size_t i = 0; i < nodes.size(); i++ )
    {
      weights.push_back( nodes[i].weight );
    }

    printf( "%d\n", maxweight( weights ) );
  }
  
  return 0;
}
